1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.io.hfile;
19 import org.apache.hadoop.hbase.classification.InterfaceAudience;
20 import org.apache.hadoop.hbase.HConstants;
21 import org.apache.hadoop.hbase.io.HeapSize;
22 import org.apache.hadoop.hbase.io.compress.Compression;
23 import org.apache.hadoop.hbase.io.crypto.Encryption;
24 import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
25 import org.apache.hadoop.hbase.util.Bytes;
26 import org.apache.hadoop.hbase.util.ChecksumType;
27 import org.apache.hadoop.hbase.util.ClassSize;
28
29
30
31
32
33
34 @InterfaceAudience.Private
35 public class HFileContext implements HeapSize, Cloneable {
36
37 public static final int DEFAULT_BYTES_PER_CHECKSUM = 16 * 1024;
38 public static final ChecksumType DEFAULT_CHECKSUM_TYPE = ChecksumType.CRC32;
39
40
41 private boolean usesHBaseChecksum = true;
42
43 private boolean includesMvcc = true;
44
45 private boolean includesTags;
46
47 private Compression.Algorithm compressAlgo = Compression.Algorithm.NONE;
48
49 private boolean compressTags;
50
51 private ChecksumType checksumType = DEFAULT_CHECKSUM_TYPE;
52
53 private int bytesPerChecksum = DEFAULT_BYTES_PER_CHECKSUM;
54
55 private int blocksize = HConstants.DEFAULT_BLOCKSIZE;
56 private DataBlockEncoding encoding = DataBlockEncoding.NONE;
57
58 private Encryption.Context cryptoContext = Encryption.Context.NONE;
59 private long fileCreateTime;
60
61
62 public HFileContext() {
63 }
64
65
66
67
68
69 public HFileContext(HFileContext context) {
70 this.usesHBaseChecksum = context.usesHBaseChecksum;
71 this.includesMvcc = context.includesMvcc;
72 this.includesTags = context.includesTags;
73 this.compressAlgo = context.compressAlgo;
74 this.compressTags = context.compressTags;
75 this.checksumType = context.checksumType;
76 this.bytesPerChecksum = context.bytesPerChecksum;
77 this.blocksize = context.blocksize;
78 this.encoding = context.encoding;
79 this.cryptoContext = context.cryptoContext;
80 this.fileCreateTime = context.fileCreateTime;
81 }
82
83 public HFileContext(boolean useHBaseChecksum, boolean includesMvcc, boolean includesTags,
84 Compression.Algorithm compressAlgo, boolean compressTags, ChecksumType checksumType,
85 int bytesPerChecksum, int blockSize, DataBlockEncoding encoding,
86 Encryption.Context cryptoContext, long fileCreateTime) {
87 this.usesHBaseChecksum = useHBaseChecksum;
88 this.includesMvcc = includesMvcc;
89 this.includesTags = includesTags;
90 this.compressAlgo = compressAlgo;
91 this.compressTags = compressTags;
92 this.checksumType = checksumType;
93 this.bytesPerChecksum = bytesPerChecksum;
94 this.blocksize = blockSize;
95 if (encoding != null) {
96 this.encoding = encoding;
97 }
98 this.cryptoContext = cryptoContext;
99 this.fileCreateTime = fileCreateTime;
100 }
101
102
103
104
105
106 public boolean isCompressedOrEncrypted() {
107 Compression.Algorithm compressAlgo = getCompression();
108 boolean compressed =
109 compressAlgo != null
110 && compressAlgo != Compression.Algorithm.NONE;
111
112 Encryption.Context cryptoContext = getEncryptionContext();
113 boolean encrypted = cryptoContext != null
114 && cryptoContext != Encryption.Context.NONE;
115
116 return compressed || encrypted;
117 }
118
119 public Compression.Algorithm getCompression() {
120 return compressAlgo;
121 }
122
123 public void setCompression(Compression.Algorithm compressAlgo) {
124 this.compressAlgo = compressAlgo;
125 }
126
127 public boolean isUseHBaseChecksum() {
128 return usesHBaseChecksum;
129 }
130
131 public boolean isIncludesMvcc() {
132 return includesMvcc;
133 }
134
135 public void setIncludesMvcc(boolean includesMvcc) {
136 this.includesMvcc = includesMvcc;
137 }
138
139 public boolean isIncludesTags() {
140 return includesTags;
141 }
142
143 public void setIncludesTags(boolean includesTags) {
144 this.includesTags = includesTags;
145 }
146
147 public void setFileCreateTime(long fileCreateTime) {
148 this.fileCreateTime = fileCreateTime;
149 }
150
151 public boolean isCompressTags() {
152 return compressTags;
153 }
154
155 public void setCompressTags(boolean compressTags) {
156 this.compressTags = compressTags;
157 }
158
159 public ChecksumType getChecksumType() {
160 return checksumType;
161 }
162
163 public int getBytesPerChecksum() {
164 return bytesPerChecksum;
165 }
166
167 public int getBlocksize() {
168 return blocksize;
169 }
170
171 public long getFileCreateTime() {
172 return fileCreateTime;
173 }
174
175 public DataBlockEncoding getDataBlockEncoding() {
176 return encoding;
177 }
178
179 public void setDataBlockEncoding(DataBlockEncoding encoding) {
180 this.encoding = encoding;
181 }
182
183 public Encryption.Context getEncryptionContext() {
184 return cryptoContext;
185 }
186
187 public void setEncryptionContext(Encryption.Context cryptoContext) {
188 this.cryptoContext = cryptoContext;
189 }
190
191
192
193
194
195
196 @Override
197 public long heapSize() {
198 long size = ClassSize.align(ClassSize.OBJECT +
199
200 4 * ClassSize.REFERENCE +
201 2 * Bytes.SIZEOF_INT +
202
203 4 * Bytes.SIZEOF_BOOLEAN +
204 Bytes.SIZEOF_LONG);
205 return size;
206 }
207
208 @Override
209 public HFileContext clone() {
210 try {
211 return (HFileContext)(super.clone());
212 } catch (CloneNotSupportedException e) {
213 throw new AssertionError();
214 }
215 }
216
217 @Override
218 public String toString() {
219 StringBuilder sb = new StringBuilder();
220 sb.append("HFileContext [");
221 sb.append(" usesHBaseChecksum="); sb.append(usesHBaseChecksum);
222 sb.append(" checksumType="); sb.append(checksumType);
223 sb.append(" bytesPerChecksum="); sb.append(bytesPerChecksum);
224 sb.append(" blocksize="); sb.append(blocksize);
225 sb.append(" encoding="); sb.append(encoding);
226 sb.append(" includesMvcc="); sb.append(includesMvcc);
227 sb.append(" includesTags="); sb.append(includesTags);
228 sb.append(" compressAlgo="); sb.append(compressAlgo);
229 sb.append(" compressTags="); sb.append(compressTags);
230 sb.append(" cryptoContext=[ "); sb.append(cryptoContext); sb.append(" ]");
231 sb.append(" ]");
232 return sb.toString();
233 }
234
235 }